#define _CRT_SECURE_NO_WARNINGS 1

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct Stu
{
	char name[20];
	int age;
};
int fufu1(const void* pa1, const void* pa2)
{
	return ((struct Stu*)pa1)->age - ((struct Stu*)pa2)->age;
}
int fufu2(const void* pa1, const void* pa2)
{
	return strcmp(((struct Stu*)pa1)->name, ((struct Stu*)pa2)->name);
}
void fufu3(char* pa1, char* pa2, size_t n)
{
	int i = 0;
	for (i = 0; i < n; i++)
	{
		char tmp = *pa1;
		*pa1 = *pa2;
		*pa2 = tmp;
		pa1++;
		pa2++;
	}
}
void fufu(void* arr, size_t sz, size_t n, int(*pa)(const void* pa1, const void* pa2))
{
	int  i = 0;
	for (i = 0; i < sz - 1; i++)
	{
		int j = 0;
		for (j = 0; j < sz - 1 - i; j++)
		{
			if ((pa)((char*)arr + j * n, (char*)arr + (j + 1) * n)>0)
			{
				fufu3((char*)arr + j * n, (char*)arr + (j + 1) * n, n);
			}
		}
	}
}
void test()
{
	struct Stu arr[] = { {"zhangsan",20},{"lisi",18},{ "wangwu",28 } };
	int sz = sizeof(arr) / sizeof(arr[0]);
	fufu(arr, sz, sizeof(arr[0]), fufu2);
	int i = 0;
	for (i = 0; i < sz; i++)
	{
		printf("%s %d\n", arr[i].name, arr[i].age);
	}
}
int main()
{
	test();
	return 0;
}